/**/
#include "global.h"
#include "rsa_incl.h"
#include "rsaref.h"
#include "rsa.h"
#include "md5.h"
#include "des.h"
#include "nn.h"
#include "ied.h"
/*
char DecryptData(char *inbuf,char *outbuf,long len)
{
  char key[]={'j','k','l',';','m',',','.','/'};
  return DesDo(outbuf,inbuf,len,key,sizeof(key),DECRYPT);
}


char EncryptData(char *inbuf,char *outbuf,long len)
{
  char key[]={'j','k','l',';','m',',','.','/'};
  return DesDo(outbuf,inbuf,len,key,sizeof(key),ENCRYPT);
}*/

char VerifyLicence(char *id,char *sn,char *licence,int len)
{
  unsigned char publickey[]={
0x00,0x04,0xb5,0x18,0xdf,0xfa,0x9d,0xbd,0x72,0x4d,0x8f,0xde,0xf6,0x26,0x42,0xea,
0x9c,0xa3,0x23,0x79,0xea,0x8e,0x76,0x0d,0x00,0x8f,0x58,0x7f,0x55,0x8b,0x8c,0x95,
0x96,0x02,0x11,0xf9,0xe5,0xae,0x5b,0x5b,0xaf,0x55,0xbd,0x4e,0x88,0xa0,0xcb,0x0a,
0x92,0x5f,0x04,0x8e,0x92,0x74,0x52,0x6a,0xd7,0x33,0x23,0x7a,0x1f,0x6c,0x66,0xc0,
0xc7,0xa9,0xf6,0x98,0x03,0xc7,0xbf,0x2a,0xbe,0x66,0xec,0x43,0x5b,0xda,0x40,0x06,
0x68,0xe4,0x2b,0xab,0x79,0xfc,0x97,0x05,0x20,0xbe,0xae,0x9b,0x1d,0xcf,0x54,0xa5,
0xe9,0x29,0xb2,0x6f,0xb9,0x4d,0x20,0xd8,0x42,0xd0,0xdc,0x4c,0x28,0x8b,0x84,0xe0,
0x8f,0x0f,0xe4,0xe2,0x04,0x3b,0x8c,0x24,0xb9,0x2b,0xdc,0x00,0x3a,0x88,0xd2,0x51,
0x67,0xe9,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x00,0x01
  };
  
  unsigned char privatekey[]={    
  
0x00,0x04,0xb5,0x18,0xdf,0xfa,0x9d,0xbd,0x72,0x4d,0x8f,0xde,0xf6,0x26,0x42,0xea,
0x9c,0xa3,0x23,0x79,0xea,0x8e,0x76,0x0d,0x00,0x8f,0x58,0x7f,0x55,0x8b,0x8c,0x95,
0x96,0x02,0x11,0xf9,0xe5,0xae,0x5b,0x5b,0xaf,0x55,0xbd,0x4e,0x88,0xa0,0xcb,0x0a,
0x92,0x5f,0x04,0x8e,0x92,0x74,0x52,0x6a,0xd7,0x33,0x23,0x7a,0x1f,0x6c,0x66,0xc0,
0xc7,0xa9,0xf6,0x98,0x03,0xc7,0xbf,0x2a,0xbe,0x66,0xec,0x43,0x5b,0xda,0x40,0x06,
0x68,0xe4,0x2b,0xab,0x79,0xfc,0x97,0x05,0x20,0xbe,0xae,0x9b,0x1d,0xcf,0x54,0xa5,
0xe9,0x29,0xb2,0x6f,0xb9,0x4d,0x20,0xd8,0x42,0xd0,0xdc,0x4c,0x28,0x8b,0x84,0xe0,
0x8f,0x0f,0xe4,0xe2,0x04,0x3b,0x8c,0x24,0xb9,0x2b,0xdc,0x00,0x3a,0x88,0xd2,0x51,
0x67,0xe9,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x00,0x01,0x9c,0x28,0x96,0xfa,0xc4,0x8a,0x57,0xc6,0x0a,0x09,0x78,0xb8,0x05,0x7b,
0xc9,0x15,0xe3,0xc1,0x7d,0x40,0xdb,0x0a,0xdb,0x30,0xc0,0x5f,0x0c,0xa5,0x08,0xd4,
0xf4,0x45,0x54,0xba,0xe8,0x13,0x31,0x34,0x1e,0x3d,0x10,0xc0,0x67,0x90,0x3f,0x85,
0x1e,0x32,0x50,0xfb,0x9f,0xce,0x2e,0x43,0x72,0xcd,0xe6,0x09,0xa8,0x8f,0x11,0x0b,
0xab,0x1e,0xb0,0xda,0x8a,0xc5,0x8d,0xcc,0xa9,0xff,0x82,0x59,0x2d,0xaf,0x83,0x6d,
0xe2,0xc3,0x70,0xb2,0xb1,0x47,0x05,0x28,0x96,0x36,0x49,0x03,0x1b,0x98,0xad,0x00,
0x91,0x4d,0xd9,0xb5,0x6b,0x00,0x8d,0xbc,0x3c,0xf5,0xc4,0xba,0x57,0xc8,0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,0x66,0x21,0xa6,0xa1,
0x78,0xf0,0x23,0xbc,0x5d,0x39,0xe7,0x1b,0x25,0x30,0xef,0xa5,0x2c,0x53,0x9c,0x35,
0x4a,0x1a,0x89,0x8f,0xe7,0x5a,0x7d,0xd5,0x96,0x5a,0x97,0x02,0x31,0x76,0xf5,0x9f,
0xb4,0x96,0xbd,0xf1,0xa6,0x60,0x40,0x2a,0x3f,0x0c,0x86,0x56,0x5a,0x79,0xa3,0xea,
0x3b,0x51,0x0b,0x7c,0x8b,0xf5,0x7e,0xf4,0x57,0x2a,0x6d,0x21,0x55,0x5e,0xac,0xae,
0x4b,0x76,0x79,0x69,0x1f,0xae,0xdc,0xbe,0x78,0xb1,0xc9,0xff,0xfe,0xa1,0x3d,0x2e,
0x94,0x1c,0x31,0xfd,0x76,0x02,0xb2,0x2d,0x2d,0xa7,0x69,0x2d,0x4a,0x37,0xbe,0xfe,
0x02,0xdb,0xea,0xa2,0x64,0x5b,0xa0,0x58,0x9f,0x9d,0x65,0x6b,0x50,0x11,0xc5,0x43,
0x50,0x7b
  };

  unsigned char dat[MAX_RSA_MODULUS_LEN];
  unsigned int dlen;  

  MD5_CTX ctx;
  unsigned char md5[16];
  MD5Init(&ctx);
  MD5Update(&ctx,id,strlen(id)); 
  MD5Update(&ctx,sn,strlen(sn));
  MD5Final(md5, &ctx);

  RSAPrivateEncrypt(dat,&dlen,md5,sizeof(md5),privatekey);
  RSAPublicDecrypt(dat,&dlen,dat,dlen,publickey);
  return 0;
}